package com.leyou.controller;

import com.leyou.dto.SpecGroupDTO;
import com.leyou.dto.SpecParamDTO;
import com.leyou.service.SpecGroupServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecController {
    @Autowired
    private SpecGroupServcie specGroupServcie;
    /*
    * 根据分类id查询规格组
    * */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCid(
           @RequestParam("id") Long cid){
        return ResponseEntity.ok(specGroupServcie.queryGroupByCid(cid));
    }

    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParamsByGid(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean searching
    ){
        return ResponseEntity.ok(specGroupServcie.querySpecParamByGid(gid,cid,searching));
    }

    /**
     * 根据分类id查询规格组以及组内参数
     * @param id 分类id
     * @return 组的集合已经组内参数集合
     */
    @GetMapping("/list")
    public ResponseEntity<List<SpecGroupDTO>> querySpecs(@RequestParam("id") Long id){
        return ResponseEntity.ok(specGroupServcie.querySpecs(id));
    }

}
